﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Configuration;
using System.Web;
using System.IO;
using System.Web.Configuration;
namespace NhanAi.DAO
{
   public class DBConnection
    {
       protected OleDbConnection conn;
       static string strConn = null;
        public DBConnection()
        {
            try
            {
               
                if (strConn == null)
                {
                    strConn = WebConfigurationManager.ConnectionStrings["conn"].ConnectionString;
                   // strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=f:\\hm_nhanaidb.mdb;";
                }
                conn = new OleDbConnection(strConn);
            }
            catch (Exception ex) { 
                //log.Info(ex.Message); 
                throw ex; }
        }
        public bool Connect()
        {
            bool result = false;
            try
            {
                if (conn.State == System.Data.ConnectionState.Closed) conn.Open();
                else
                {
                    conn.Close();
                    conn.Open();
                }
                result = true;
            }
            catch (OleDbException ex)
            {
                //log.Info(ex.Message);
                throw ex;
            }
            catch (Exception ex)
            {
                //log.Info(ex.Message);
                throw ex;
            }
            return result;
        }
        public void Disconnect()
        {
            try
            {
                conn.Close();
            }
            catch (OleDbException ex) {// log.Info(ex.Message);
                throw ex; }
            catch (Exception ex) { //log.Info(ex.Message);
                throw ex; }
        }
    }
}
